package com.tenement.utils.base;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

public class ProduceUtil {

	public static String genId(String machineId) {
		String orderId = machineId + (System.currentTimeMillis() + "").substring(1)
				+ (System.nanoTime() + "").substring(7, 10);
		return orderId;
	}

	public static void main(String[] args) {
		/*
		 * for (int i = 1; i <= 1000; i++) {
		 * System.out.println(getOrderIdByUUId("1"));
		 * 
		 * }
		 */
		System.out.println(productNowDate());
		System.out.println(getOrderIdByUUId("1"));
	}

	/**
	 * 生成订单号
	 * 
	 * @param machineId
	 * @return
	 */
	public static String getOrderIdByUUId(String machineId) {

		int hashCodeV = UUID.randomUUID().toString().hashCode();
		if (hashCodeV < 0) {// 有可能是负数
			hashCodeV = -hashCodeV;
		}
		System.out.println(hashCodeV);
		// 0 代表前面补充0
		// 4 代表长度为4
		// d 代表参数为正数型
		String orderId = machineId + String.format("%015d", hashCodeV);
		return orderId;
	}

	/**
	 * 生成当前时间
	 * 
	 * @return
	 */
	public static String productNowDate() {
		Date day = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String s = df.format(day);
		return s;
	}

	/**
	 * 生成六位数的验证码
	 * 
	 * @return
	 */
	public static String productCode() {
		String code = "";
		Random random = new Random();
		for (int i = 0; i < 6; i++) {
			code += random.nextInt(10);
		}
		return code;
	}
	
	/**
	 * 生成账号
	 * @return
	 */
	public static String getStringRandom() {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < 7; i++) {

			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 输出字母还是数字
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 输出是大写字母还是小写字母
				int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (random.nextInt(26) + temp);
			} else if ("num".equalsIgnoreCase(charOrNum)) {
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val.toLowerCase();
	}
}
